#include "mode_display_handle.h"

void disp_light_handle(u8 *buf)  //通用灯带发送程序 
{
    for (int i = 0; i<get_color_length(); i++) //以总长度那根进行计算
    {
        float brightnessFactor =((float)(get_brighness_level()+1)/(float)101);
        AdjustBrightness(brightnessFactor,&buf[i+0],&buf[i+1],&buf[i+2]);
    }
    //printf("get_brighness_level() is %d\n",get_brighness_level());
    send_spi1_msg(buf,get_color_length());
    u8 buf_temp[BUF_SIZE];

    memcpy(buf_temp,buf,LED2_NUMBER*3);
    send_spi2_msg(buf_temp,LED2_NUMBER*3);
}

void disp_light1_handle(u8 *buf) //一号灯带数据发送程序
{
    send_spi1_msg(buf,get_color_length()); 
}

void disp_light2_handle(u8 *buf) //二号灯带数据发送程序
{
    send_spi2_msg(buf,LED2_NUMBER*3);
}

void set_cw_light(u8 *param)
{
    //if(get_flag()== 1)
    {
        u32 *uart_rx_buffer = NULL;
        uart_rx_buffer = (u32 *)pvPortMalloc(sizeof(u32*)*(2));
        bzero(uart_rx_buffer,sizeof(u32*)*(2));
        uart_rx_buffer[0]= (u32)(PWM_SUM*param[0]/100*(get_cw_config_brighness()+1)/101*60/100); //W
        uart_rx_buffer[1]= (u32)(PWM_SUM*param[1]/100*(get_cw_config_brighness()+1)/101*60/100); //R
        xQueueSend(pwm_queue_handle,&uart_rx_buffer,0);
        uart_rx_buffer=NULL;
    }
}


void set_cw_light_other(u8 *param)
{
    //if(get_flag()== 1)
    {
        u32 *uart_rx_buffer = NULL;
        uart_rx_buffer = (u32 *)pvPortMalloc(sizeof(u32*)*(2));
        bzero(uart_rx_buffer,sizeof(u32*)*(2));
        uart_rx_buffer[0]= (u32)(PWM_SUM*param[0]/100*(get_cw_config_brighness()+1)/101*60/100); //W
        uart_rx_buffer[1]= (u32)(PWM_SUM*param[1]/100*(get_cw_config_brighness()+1)/101*60/100); //R
        xQueueSend(pwm_queue_handle,&uart_rx_buffer,0);
        uart_rx_buffer=NULL;
    }
}

void disp_light_handle_other(u8 *buf)  //特殊发送灯光函数
{
    //printf("get_brighness_level() is %d\n",get_brighness_level());
    send_spi1_msg(buf,get_color_length());
    u8 buf_temp[BUF_SIZE];

    memcpy(buf_temp,buf,LED2_NUMBER*3);
    send_spi2_msg(buf_temp,LED2_NUMBER*3);
}

void disp_clear_light1()
{
    u8 buf[BUF_SIZE];
    bzero(buf,BUF_SIZE);
    disp_light_handle(buf);
}

void disp_clear_light2()
{
    u8 buf[BUF_SIZE];
    bzero(buf,BUF_SIZE);
    disp_light_handle(buf);
}

void disp_clear_cw_light()
{
    u8 buf[2];
    bzero(buf,2);
    buf[0]=0;
    buf[1]=0;
    set_cw_light_other(buf);
}